import 'dart:convert';
import 'package:flutter_mark_trip/model/travel_tab_model.dart';
import 'package:http/http.dart' as http;

///旅拍类别dao层
const TRAVEL_TAB_URL = 'http://www.devio.org/io/flutter_app/json/travel_page.json';
class TravelTabDao{
  /*
   * 旅拍类别
   */
  static Future<TravelTabModel> fetch() async{
    final response = await http.get(TRAVEL_TAB_URL);
    if(response.statusCode == 200){
      Utf8Decoder utf8decoder = Utf8Decoder();//fix 中文乱码
      var result = json.decode(utf8decoder.convert(response.bodyBytes));
      return TravelTabModel.fromJson(result);
    }else{
      //抛出异常，加载接口数据失败时
      throw Exception('Failed to load travel_page.json');
    }
  }
}